﻿@using OpenIdProvider
@model OpenIdProvider.Models.User

@{
    var email = Model.Email;
    var realName = Model.RealName;

    var lastActivity = Model.LastActivityDate;

    ViewData["Title"] = "User - " + email;
}

<div class="user-info">
    <table width="100%">
        <tr>
            <td>
                <div>
                    @if (realName != null)
                    {
                        <text>
                            <div class="user-attribute">Real Name</div>
                            <div class="user-attribute-value real-name">@realName</div>
                        </text>
                    }

                    <div class="user-attribute">Last Seen</div>
                    <div class="user-attribute-value">@lastActivity.ToRelativeTimeSpan()</div>

                    @if (Model.VanityProviderId.HasValue())
                    {
                        var vanityUrl = Model.GetVanityClaimedIdentifier().AbsoluteUri;
                        <text>
                        <div class="user-attribute">Vanity Id</div>
                        <div class="user-attribute-value"><a href="@vanityUrl">@vanityUrl</a></div>
                        </text>
                    }

                    <div class="edit-profile">
                    @if (Current.LoggedInUser.IsAdministrator)
                    {
                        <a href="/user/@(Model.ProviderId)/edit">Edit Profile</a>
                    }
                    else
                    {
                        <a href="/user/edit">Edit Profile</a>
                    }
                </div>
            </td>
            <td>
                <div class="id-card" style="float:right"></div>
            </td>
        </tr>
    </table>

    <a href="#" onclick="$('#delegate').attr('style', ''); $(this).remove();">Use your own URL to log in</a>

    <div id="delegate" style="visibility:hidden;height:0px;">
        <p>If you want to use your own URL to log in, add the following two tags to the head of the HTML:</p>
        <code>
            &lt;link rel="openid2.provider" href="@(Current.Url("openid/provider"))"&gt;<br>
            &lt;link rel="openid2.local_id" href="@(Model.GetClaimedIdentifier())"&gt;
        </code>
        <p>This is known as OpenID delegation.</p>
    </div>
</div>

<div class="user-history">
    <h3>History</h3>
    <table class="tbl-data">
        <thead>
            <tr>
                <th>Type</th>
                <th>Comment</th>
                <th>IP</th>
                <th>Date</th>
            </tr>
        </thead>
        @{
            var even = true;
            foreach (var h in Model.GetHistory())
            {
                <tr class="@(even ? "even" : "odd")">
                    <td>@OpenIdProvider.Models.UserHistoryTypeId.GetDisplayName(h.UserHistoryTypeId)</td>
                    <td>@h.Comment</td>
                    <td>@h.IP</td>
                    <td>@h.CreationDate.ToRelativeTimeSpan()</td>
                </tr>
                
                even = !even;
            }
        }
    </table>
</div>